package demo4;

/*
某软件公司欲开发一款汽车竞速类游戏，需要模拟长轮胎和短轮胎急刹车时在路面上留下的不同痕迹，
并考虑后续能模拟更多种轮胎急刹车时的痕迹。现采用策略(Strategy)设计模式来实现该需求，所设计的类图如下所示：

image.png

请编码实现模拟长轮胎和短轮胎急刹车时在路面上留下的不同痕迹。完整程序结构如下，本题已经提供了接口BrakeBehavior的定义以及main函数部分，请自行编写并提交红色提示部分代码！

interface BrakeBehavior {

    public abstract void stop();

}

public class Main {

    public static void main(String[] args) {

        BrakeBehavior brake1 = new ShortWheelBrake();

        BrakeBehavior brake2 = new LongWheelBrake();

        Car car = new ShortWheelCar(brake1);

        car.brake();

        car = new LongWheelCar(brake2);

        car.brake();

    }

}

    输入描述
            无输入数据

输出描述
        Simulate short tire brake marks!

        Simulate long tire brake marks!

        提示
        只需要提交部分代码！

        样例输入  复制  更多
        样例输出
        Simulate short tire brake marks!
        Simulate long tire brake marks!
        允许最长运行时间
        1000ms
        允许使用最大内存
        64MB
 */


interface BrakeBehavior {

    public abstract void stop();

}
class ShortWheelBrake implements  BrakeBehavior{
    public ShortWheelBrake(){

    }
    @Override
    public void stop() {
        System.out.println("Simulate short tire brake marks!");
    }
}

class LongWheelBrake implements  BrakeBehavior{
    public LongWheelBrake(){

    }
    @Override
    public void stop() {
        System.out.println("Simulate long tire brake marks!");
    }
}


abstract class Car {
    protected BrakeBehavior brakeBehavior;
    public abstract void brake();


}

class ShortWheelCar extends Car{
    public ShortWheelCar(BrakeBehavior shortWheelBrake){
        super.brakeBehavior = shortWheelBrake;
    }
    public void brake(){
        this.brakeBehavior.stop();

    }
}
class LongWheelCar extends Car{
    public LongWheelCar(BrakeBehavior longWheelBrake){
        super.brakeBehavior=longWheelBrake;
    }
    public void brake(){
        this.brakeBehavior.stop();

    }
}


public class Main {

    public static void main(String[] args) {

        BrakeBehavior brake1 = new ShortWheelBrake();

        BrakeBehavior brake2 = new LongWheelBrake();

        Car car = new ShortWheelCar(brake1);

        car.brake();

        car = new LongWheelCar(brake2);

        car.brake();

    }

}
